//
//  BindingWeChatView.swift
//  YLH
//
//  Created by qinjiangtao on 2024/1/11.
//

import UIKit

class BindingWeChatView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .white
        addUI()
    }
    
    private func addUI() {
        self.addRoundedCorners(withRadius: 10, byRoundingCorners: [.topLeft, .topRight] )
        
        let logoImgView = UIImageView().then {
            $0.frame = CGRect(x: 0, y: 65, width: 60, height: 60)
            $0.centerX = SCREEN_WIDTH * 0.25
            $0.image = UIImage(named: "logo")
            $0.contentMode = .scaleAspectFill
            $0.addRoundedCorners(withRadius: 30)
            $0.clipsToBounds = true
        }
        self.addSubview(logoImgView)
        
        let bindingImgView = UIImageView().then {
            $0.frame = CGRect(x: 0, y: 75, width: 42, height: 42)
            $0.centerX = SCREEN_WIDTH * 0.5
            $0.image = UIImage(named: "绑定")
            $0.contentMode = .scaleAspectFill
            $0.clipsToBounds = true
        }
        self.addSubview(bindingImgView)
        
        let weChatImgView = UIImageView().then {
            $0.frame = CGRect(x: 0, y: 75, width: 42, height: 42)
            $0.centerX = SCREEN_WIDTH * 0.75
            $0.image = UIImage(named: "微信_登录")
//            $0.contentMode = .scaleAspectFill
            $0.clipsToBounds = true
        }
        self.addSubview(weChatImgView)
        
        let bindingBtn = UIButton().then {
            $0.frame = CGRect(x: 20, y: 168, width: SCREEN_WIDTH - 50, height: 50)
            $0.backgroundColor = MainColor
            $0.titleLabel?.font = SYSFONT(ofSize: 14)
            $0.setTitle("去绑定", for: .normal)
            $0.setTitleColor(.white, for: .normal)
            $0.addRoundedCorners(withRadius: 25)
            $0.addTarget(self, action: #selector(bindingBtnClick), for: .touchUpInside)
        }
        self.addSubview(bindingBtn)
    }
    
    @objc private func bindingBtnClick() {
//        let ctl = ImproveInfoViewController()
//        self.viewController().navigationController?.pushViewController(ctl, animated: true)
        
        let req = SendAuthReq()
        req.scope = "snsapi_userinfo"
        req.state = "yh"
        WXApi.send(req) { isSuccess in
            print(isSuccess)
            ShowHUD(str: "微信跳转失败")
        }
//        WXApi.sendAuthReq(req, viewController: self.viewController(), delegate: nil)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
